<section class="content-header">
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li><a href="#">支付管理</a></li>
        <li class="active">产品配置</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="jax-box">
        <form id="selectForm" class="form-inline" th:action="@{/channelAttr/list}" role="form">
            <div class="form-group">
                <div class="form-group">
                    <label class="control-label">类型名称：</label>
                    <div class="control-inline">
                        <input type="text" name="service" class="form-control" />
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label" for="flag">产品类型：</label>
                    <select id="flag" name="flag" class="form-control">
                        <option value="">==请选择==</option>
                        <option value="0">交易类型</option>
                        <option value="1">余额代付类型</option>
                        <option value="2">垫资代付类型</option>
                    </select>
                </div>

                <shiro:hasPermission name="channelAttr:list">
                    <div class="btn-group btn-group-sm" style="text-align:left;">
                        <button type="button" id="btn_query" class="btn btn-info">查询</button>
                        <button type="reset" id="btn_reset" class="btn btn-warning">重置</button>
                    </div>
                </shiro:hasPermission>
            </div>
        </form>
    </div>
    <div class="jax-box jax-box-table">
        <div id="toolbar" class="toolbar btn-group">
            <shiro:hasPermission name="channelAttr:add">
                <button id="btn_add" type="button" class="btn btn-primary" data-toggle="modal" data-target="#channelAttrModal">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
                </button>
            </shiro:hasPermission>
            <!--<shiro:hasPermission name="channelAttr:batchDelete">
                <button id="btn_batch_delete" type="button" class="btn btn-danger">
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>批量删除
                </button>
            </shiro:hasPermission>-->
        </div>


        <div class="wrapper-content">
            <div class="ibox-content animated fadeInRight">
                <div class="jqGrid_wrapper">
                    <table id="table_list"></table>
                    <div id="pager_list"></div>
                </div>
            </div>
        </div>

    </div>
</section>

<!--产品配置新增模态框-->
<div id="channelAttrModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">新增产品配置</h4>
            </div>
            <div class="modal-body">
                <div>
                    <form class="form-horizontal" id="channelAttrForm" method = 'post' th:action="@{/channelAttr/add}">
                        <div class="box-body">
                            <div class="form-group required">
                                <label for="service" class="col-sm-3 control-label form-required">类型名称 :</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="service" id="service" require="必填项"  placeholder="" />
                                </div>
                            </div>
                            <div class="form-group required">
                                <label for="balanceName" class="col-sm-3 control-label form-required">余额名称 :</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="balanceName" id="balanceName" require="必填项" placeholder="" />
                                </div>
                            </div>

                            <div class="form-group required">
                                <label  class="col-sm-3 control-label form-required">结算类型 :</label>
                                <div class="col-sm-8">
                                    <select name="settle" class="form-control" require="必填项">
                                        <option value="">=请选择=</option>
                                        <option value="D0">D0</option>
                                        <option value="T1">T1</option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group required">
                                <label  class="col-sm-3 control-label form-required">产品类型 :</label>
                                <div class="col-sm-8">
                                    <select name="flag" class="form-control" requireZero="必填项">
                                        <option value="">=请选择=</option>
                                        <option value="0">交易产品类型</option>
                                        <option value="1">余额代付类型</option>
                                        <option value="2">垫资代付类型</option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group required">
                                <label for="minTip" class="col-sm-3 control-label form-required">产品费率 :</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="minTip" id="minTip" require="必填项" number="格式不正确，只能输入数字" placeholder="" />
                                </div>
                            </div>

                            <div class="form-group required">
                                <label for="remark" class="col-sm-3 control-label form-required">通道名称 :</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="remark" id="remark" require="必填项" placeholder="" />
                                </div>
                            </div>

                        </div>
                        <!-- /.box-body -->
                        <div class="box-footer">
                            <div class="pull-right">
                                <button type="button" id="saveChanelAttr" class="btn btn-info">确定</button>
                                <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
                            </div>
                        </div>
                        <!-- /.box-footer -->
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 产品配置详情模态框 -->
<div id="channelAttrDetailModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">产品配置信息</h4>
            </div>
            <div class="modal-body">
                <div id="channelAttrOpenWindow">
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

<script type="text/javascript">
    $(document).ready(function () {
        var editFlag = "[[${@perms.hasPerm('channelAttr:edit')}]]";
        //var deleteFlag = "[[${@perms.hasPerm('channelAttr:delete')}]]";

        var dataGrid = new DataGrid({

            dataGrid: $('#table_list'),
            searchForm: $('#selectForm'),
            dataGridPage: $('#pager_list'),
            multiselect: true,
            multiboxonly: true,
            rownumbers: true,
            rownumWidth: 60,
            colModel: [
                {
                    header: '类型名称',
                    name: 'service',
                    index: 'service',
                    editable: false,
                    width: 80,
                    sortable: false,
                    search: false
                },
                {
                    header: '结算类型',
                    name: 'settle',
                    index: 'settle',
                    editable: true,
                    width: 30,
                    sortable: false
                },
                {
                    header: '产品类型',
                    name: 'flag',
                    index: 'flag',
                    editable: true,
                    width: 50,
                    sortable: false,
                    formatter: function (value) {
                        switch (value) {
                            case 0:
                                return '交易类型';
                            case 1:
                                return '余额代付类型';
                            case 2:
                                return '垫资代付类型';
                            default:
                                return "";
                        }
                    }
                },
                {
                    header: '备注',
                    name: 'remark',
                    index: 'remark',
                    editable: true,
                    width: 50,
                    sortable: false
                },
                {
                    header: '操作',
                    name: 'operate',
                    index: 'operate',
                    width: 80,
                    align: 'center',
                    sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        //var edit = editFlag == "true" ? '<a class="table-btn table-btn-info" href="javascript:void(0)" onclick="editChannelAttr(\'' + rowObject.service + '\')">编辑</a>' : '';
                        //var del = deleteFlag == "true" ? '<a  class="table-btn table-btn-danger" href="javascript:void(0)" onclick="deleteAgent(' + rowObject.id + ')">删除</a>' : '';

                        var edit = '<a class="table-btn table-btn-info" href="javascript:void(0)" onclick="editChannelAttr(\'' + rowObject.service + '\')">编辑</a>' ;
                        var del = '<a class="table-btn table-btn-danger" href="javascript:void(0)" onclick="deleteChannelAttr(\'' + rowObject.service + '\')">删除</a>';
                        return edit + del;
                    }
                }
            ]
            //gridComplete:renderSwitch
        });

        //加载表格
        $("#btn_query").click(function () {
            $("#table_list").jqGrid('setGridParam', {
                datatype: 'json',
                postData: {
                    service: $('input[name=service]').val()
                }, // 发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入
        });

        //新增-保存
        $("#saveChanelAttr").click(function(){
            if(doValidForm(channelAttrForm)){
                Core.mask("#saveChanelAttr");
                Core.postAjax(ctxPath + "/channelAttr/add",$("#channelAttrForm").serialize(),function (data) {
                    Core.unmask("#saveChanelAttr");
                    if(data.code==200){
                        $("#channelAttrModal").modal("hide");
                        $("#channelAttrForm")[0].reset();
                        Core.refreshJqTable("#table_list");
                    }
                    layer.msg(data.msg);
                })
            };
        });

        // var roleId="";
        // var agentIdStr;//批量
        // //批量删除
        // $("#btn_batch_delete").click(function(){
        //     var checkedRows= Core.selectJqMutiData("#table_list");
        //     if(checkedRows!=false){
        //         Core.confirm("确定删除选中的"+checkedRows.length+"条记录？",function () {
        //             agentIdStr="";
        //             $.each(checkedRows, function (i, item) {
        //                 var rowData = $("#table_list").jqGrid('getRowData', checkedRows[i]);
        //                 agentIdStr+=(rowData.id+",");
        //             });
        //             agentIdStr=agentIdStr.substring(0,agentIdStr.length-1);
        //             Core.postAjax(ctxPath + "/agent/batch/delete",{"agentIdStr":agentIdStr},function(data){
        //                 if(data.code==200){
        //                     Core.refreshJqTable("#table_list");
        //                 }
        //                 layer.msg(data.msg);
        //             },"get")
        //         })
        //     }
        // });

    });

    /*删除*/
    function deleteChannelAttr(service) {
        Core.confirm("确定删除该产品类型？",function () {
            Core.postAjax(ctxPath + "/channelAttr/delete", {"service": service}, function (data) {
                if (data.code == 200) {
                    Core.refreshJqTable("#table_list");
                }
                layer.msg(data.msg);
            }, "get")
        })
    }

    /*编辑*/
    function editChannelAttr(service) {
        Core.load("#channelAttrOpenWindow", ctxPath + "/channelAttr/edit?&service=" + service, function () {
            $("#channelAttrDetailModal").modal("show");
        }, 2);
    }

</script>
